package org.melanesia.converters;

import java.sql.CallableStatement;

import org.melanesia.converters.exceptions.ConversionException;

/**
 * JavaToJdbcConverter is an interface for implementation of converters from
 * java to jdbc type. This converters are used in the process of mapping Java
 * objects to jdbc statement in/out parameters. Note, that every object passed
 * as the parameter is required to have a JavaToJdbcConverter that will convert
 * its value into an appropriate jdbc type.
 *
 * @see org.melanesia.converters.TypeConverter#registerConverter(Class, JavaToJdbcConverter)
 *
 * @author marcin.kielar
 */
public interface JavaToJdbcConverter {

    /**
     * Returns JDBC Type that should be used with converted value.
     *
     * @see java.sql.Types
     * @return JDBC Type
     */
    int getJdbcType();

    /**
     * Converts value into a form that is applicable to CallableStatememt
     * object.
     *
     * @param value
     *            value to convert
     * @param stmt
     *            instance of CallableStatement that this value is passed to
     * @param parameterName
     *            name of the parameter that this value is associated with
     * @return converted value
     * @throws ConversionException
     *            when conversion fails
     */
    Object convert(Object value, CallableStatement stmt, String parameterName) throws ConversionException;
}
